﻿@using System.Globalization
@using Orchard.Autoroute.Services
@using Orchard.ContentManagement
@using Orchard.ContentManagement.Aspects
@using Orchard.Localization.Services
@{
    var localizableAspects = Enumerable.Empty<ILocalizableAspect>();
    var homePage = WorkContext.Resolve<IHomeAliasService>().GetHomePage();

    if (homePage != null && homePage.Has<ILocalizableAspect>()) {
        var localizationService = WorkContext.Resolve<ILocalizationService>();
        localizableAspects = localizationService.GetLocalizations(homePage).Concat(new[] { homePage.As<ILocalizableAspect>() });
    }
}
@if (localizableAspects.Any()) {
<div>
    <ul>
        @foreach (var localization in localizableAspects) {

            if (localization.Culture == null) {
                continue;
            }

            var culture = CultureInfo.GetCultureInfo(localization.Culture);

            <li>
                @if (localization.Culture.Equals(WorkContext.CurrentCulture, StringComparison.InvariantCultureIgnoreCase)) {
                    <a href="@Url.ItemDisplayUrl(localization)">@T("{0} (current)", culture.DisplayName)</a>
                }
                else {
                    <a href="@Url.ItemDisplayUrl(localization)">@T("{0}", culture.DisplayName)</a>
                }
            </li>
        }
    </ul>
</div>
}
